/**
 * This class represents a productgroup-handler
 * 
 * @author Konrad Paumann
 * @author Bernhard Denner
 * @author Maximilian Csuk
 * 
 * $Revision: 63 $ 
 * $Date: 2007-10-19 17:32:10 +0200 (Fri, 19 Oct 2007) $
 * 
 */

public class ProductGroupHandler extends Handler {
	/**
	 * variables
	 */
	private final ProductGroup productGroup;
	
	/**
	 * constructor
	 * @param g the product-group to handle
	 */
	public ProductGroupHandler(ProductGroup productGroup, User user) {
		super(user);
		assert productGroup != null;
		this.productGroup = productGroup;
	}
	
	/**
	 * adds a product to the group, if the user has the appropriate rights
	 * @param user the user who wants to add a product
	 * @throws UserException
	 */
	public void addProduct(String shortDescription, String description, int price,
			int amount) throws UserException, ProductException {
		if (!user.canWrite())
			throw new UserException("User nicht authorisiert");
		
		try {
			productGroup.addProduct(new Product(shortDescription, description, price, amount));
		} catch (ProductException e) {
			throw new ProductException(e.getMessage());
		}
	}
	
}
